package com.wnhz.work.yz.activity;

import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.utils.MyDialog;
import com.wnhz.work.yz.view.MyDatePicker;
import com.wnhz.work.yz.view.PickerView;

import java.util.ArrayList;
import java.util.List;

/**
 * 完善资料
 */
public class PerfectInformationActivity extends BaseActivity implements View.OnClickListener {

    private List<String> sex_lists = new ArrayList<>();
    private TextView birthday_select;
    private TextView sex_select;
    private TextView city_select;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_perfect_information);
        initTitle();



        birthday_select = (TextView) findViewById(R.id.birthday_select);
        sex_select = (TextView) findViewById(R.id.sex_select);
        city_select = (TextView) findViewById(R.id.city_select);
        sex_select.setOnClickListener(this);
        birthday_select.setOnClickListener(this);
        city_select.setOnClickListener(this);

        sex_lists.add("男");
        sex_lists.add("女");

    }

    private TextView title;

    private void initTitle() {
        title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText(R.string.perfect_information_title);
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        findViewById(R.id.btn_main_right).setOnClickListener(this);
        findViewById(R.id.btn_main_right).setVisibility(View.VISIBLE);
        TextView title_right_tv_save = (TextView) findViewById(R.id.tv_right);
        title_right_tv_save.setVisibility(View.VISIBLE);
        title_right_tv_save.setText(R.string.title_right_tv_save);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_main_left:
                finish();
                break;
            case R.id.btn_main_right://保存
                break;
            case R.id.sex_select://性别
                closrKeyboard();
                showPopPositionWindow(v,sex_lists);
                break;
            case R.id.birthday_select://生日
                closrKeyboard();
                showDateDialog();
                break;
            case R.id.city_select://所在城市

                break;
        }
    }

    private void showDateDialog() {
        MyDatePicker dataPicker = new MyDatePicker(PerfectInformationActivity.this);
        dataPicker.selectDateDialog(birthday_select, "1992-11-01", "birth");
    }



    /**
     * -----修改性别弹wheel
     */
    private String pickIndex, pickCard;

    private void showPopPositionWindow(View view, final List<String> list) {

        // 一个自定义的布局，作为显示的内容
        View contentView = LayoutInflater.from(this).inflate(R.layout.pop_educate, null);
        final PickerView picker = (PickerView) contentView.findViewById(R.id.picker_educate);
        TextView pickersure = (TextView) contentView.findViewById(R.id.picker_submit);
        TextView pickercancel = (TextView) contentView.findViewById(R.id.picker_cancel);
        /*final PopupWindow popupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT, true);*/
        final Dialog dialog = MyDialog.getButtonDialog(this, contentView);
        ArrayList<Object> str = new ArrayList<Object>();
        for (int i = 0; i < list.size(); i++) {
            str.add(list.get(i));
        }

        picker.setData(str);
        int size = list.size();
        int defaultNum = size / 2;
        pickCard = str.get(defaultNum).toString();
        picker.setOnSelectListener(new PickerView.onSelectListener() {
            @Override
            public void onSelect(String text) {
                pickCard = text;
            }
        });

        pickercancel.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {
                dialog.hide();

            }
        });
        pickersure.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {
                if (null != pickCard) {
                    sex_select.setText(pickCard);

                }
                dialog.hide();
            }
        });

    }


}
